/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: ExceptionUtils
 * Author:   zhouheng
 * Date:     2019/6/9 11:57
 * Description:
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.zhouh.golden.web.exception;

import com.zhouh.golden.common.constants.GoldenConstant;
import lombok.extern.slf4j.Slf4j;

/**
 * 〈一句话功能简述〉<br> 
 * 〈〉
 *
 * @author zhouheng
 * @create 2019/6/9
 * @since 1.0.0
 */
@Slf4j
public class ExceptionUtils {
    /**
     * 将下层抛出的异常转换为resp返回码
     *
     * @param e Exception
     * @return
     */
    public static Exception handlerException4biz(Exception e) {
        Exception ex = null;
        if (!(e instanceof Exception)) {
            return null;
        }
        if (e instanceof ValidateException) {
            ex = new ServiceException(((ValidateException) e).getErrorCode(), ((ValidateException) e).getErrorMessage());
        }else if (e instanceof Exception) {
            ex = new ServiceException(GoldenConstant.ResponseCodeEnum.SYSTEM_BUSY);
        }
        log.error("ExceptionUtil.handlerException4biz,Exception=" + e.getMessage(), e);
        return ex;
    }
}